package Test.Test02;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class WeightedRandomSelect {
    public static void main(String[] args) {
        // 创建部门类
        class Department {
            String name;
            int weight;

            public Department(String name, int weight) {
                this.name = name;
                this.weight = weight;
            }
        }

        // 创建部门集合，每个部门的权重比例为1:2:3
        List<Department> departments = new ArrayList<>();
        departments.add(new Department("宁波", 1));
        departments.add(new Department("上海", 2));
        departments.add(new Department("厦门", 3));

        // 设定权重总和
        int totalWeight = 100;

        // 随机选择部门
        for (int i = 0; i < 100; i++) {
            int selectedIndex = new Random().nextInt(departments.size());
            Department selectedDepartment = departments.get(selectedIndex);
            System.out.println(selectedDepartment.name + "被选中");
        }
    }
}
